package com.sirdc.modules.sys.web.index;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import net.huashitong.scheduling.databean.ResourcesDatabean;
import net.huashitong.scheduling.entity.Resources;
import net.huashitong.scheduling.filter.ResourcesFilter;
import net.huashitong.scheduling.service.ResourcesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 资源清单
 */
@Controller
@RequestMapping("/index/resources")
public class IndexResourcesController extends JsonBaseController {
    @Autowired
    private ResourcesService resourcesService;

    @Override
    protected String getView(String arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    /**
     * 根据type查询
     * @param filter
     * @return
     */
    @RequestMapping("/queryTypeValue")
    @ResponseBody
    public Message queryTypeValue(@RequestBody ResourcesFilter filter){
        List<Resources> lists = resourcesService.queryByType(filter);
        List<ResourcesDatabean> databeans = new ArrayList<ResourcesDatabean>();
        for (Resources resources : lists) {
                ResourcesDatabean databean = new ResourcesDatabean();
                databean.setSysId(resources.getSysId());
                databean.setTitle(resources.getTitle());
                databeans.add(databean);
        }
        return coverMessage("200","数据获取成功",databeans);

    }

    /**
     * 详细
     * @param filter
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryDetailValue")
    public Message queryDetailValue(@RequestBody ResourcesFilter filter){
        Resources resources = resourcesService.queryDetailValue(filter);
        ResourcesDatabean databean = new ResourcesDatabean();
        databean.setText(resources.getText());
        return coverMessage("200", "数据获取成功", databean);
    }

}
